Skip to content

Conversation

jserv
Copy link
Collaborator

@jserv jserv commented Aug 26, 2025

This commit adds comprehensive pointer difference support (ptr1 - ptr2) that was missing from the existing pointer arithmetic implementation:

  • Pointer difference calculation: It computes element count by dividing byte difference by element size (char=1, int=4, etc.)
  • Expression support: Enables complex expressions like *(p + (q - r))
  • Unified element size detection: Consistent logic for both regular and typedef pointers across all arithmetic operations

@jserv jserv force-pushed the pointer-arithmetic branch 2 times, most recently from e791a2b to add8849 Compare August 28, 2025 11:04
@jserv jserv force-pushed the pointer-arithmetic branch 5 times, most recently from 96b2321 to 6ddf7fb Compare September 3, 2025 15:20
@jserv
Copy link
Collaborator Author

jserv commented Sep 4, 2025

@cubic-dev-ai review this PR

Copy link

cubic-dev-ai bot commented Sep 4, 2025

@cubic-dev-ai review this PR

@jserv I've started the AI code review. It'll take a few minutes to complete.

Copy link

@cubic-dev-ai cubic-dev-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

3 issues found across 2 files


Since this is your first cubic review, here's how it works:

  • cubic automatically reviews your code and comments on bugs and improvements
  • Teach cubic by replying to its comments. cubic learns from your replies and gets better over time
  • Ask questions if you need clarification on any suggestion

React with 👍 or 👎 to teach cubic. You can also tag @cubic-dev-ai to give feedback, ask questions, or re-run the review.

Copy link
Collaborator

@ChAoSUnItY ChAoSUnItY left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The main logic looks good, only few suggestions made by AI review in tests/driver.sh needs to change for better readability.

This improves the support for pointer difference calculations and
refactors the parser by extracting complex pointer arithmetic logic into
well-named helper functions.

Limitation:
Integer pointer differences (e.g., 'int *q - int *p') are not fully
supported due to type information loss in the compilation pipeline.
When pointer variables are loaded for use in expressions, they become
temporaries without sufficient type information to determine element
size for proper scaling.

Workaround:
For integer pointer differences, cast to char* and divide manually:
  ((char *) q - (char *) p) / sizeof(int)

Character pointer differences work correctly because element size is 1,
requiring no scaling.
@jserv jserv force-pushed the pointer-arithmetic branch from 6ddf7fb to 97996ed Compare September 4, 2025 04:16
@jserv jserv merged commit c33ef7c into master Sep 4, 2025
12 checks passed
@jserv jserv deleted the pointer-arithmetic branch September 4, 2025 04:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants